<template>
  <div>
    <p style="margin-top: 10px;">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">后台首页</el-breadcrumb-item>
        <el-breadcrumb-item>商品列表</el-breadcrumb-item>
      </el-breadcrumb>
    </p>
    <el-tabs v-model="activeName" style="width：100%;">
      <el-tab-pane label="全部" name="first">
        <div style="text-align:left;">
          <el-button type="success">发布商品</el-button>
          <el-button type="primary">批量删除</el-button>
          <el-button>上架</el-button>
          <el-button>下架</el-button>
          <el-button style="float:right;margin-right:50px;" @click="search">搜索</el-button>
          <el-input
            style="width: 40%;float:right;"
            v-model="input"
            placeholder="请输入关键字"
          ></el-input>
        </div>
        <el-table
          :data="reData"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column label="商品ID" prop="_id"></el-table-column>
          <el-table-column label="商品图片">
            <template slot-scope="scope">
              <img width="50" :src="scope.row.pic" alt />
            </template>
          </el-table-column>
          <el-table-column prop="title" label="商品名称"></el-table-column>
          <el-table-column prop="price" label="商品价钱"></el-table-column>
          <el-table-column label="操作" width="450">
            <template slot-scope="scope">
              <el-button style="margin-top:5px;">基础设置</el-button>
              <el-button style="margin-top:5px;">商品规格</el-button>
              <el-button style="margin-top:5px;">商品属性</el-button>
              <el-button style="margin-top:5px;">媒体设置</el-button>
              <el-button style="margin-top:5px;">商品详情</el-button>
              <el-button style="margin-top:5px;">折扣设置</el-button>
              <el-button style="margin-top:5px;">删除商品</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageIndex"
          :page-sizes="[8,10,15,20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.length"
        ></el-pagination>
      </el-tab-pane>
      <el-tab-pane label="审核中" name="second">审核中</el-tab-pane>
      <el-tab-pane label="出售中" name="third">出售中</el-tab-pane>
      <el-tab-pane label="已下架" name="fourth">已下架</el-tab-pane>
      <el-tab-pane label="库存预警" name="five">库存预警</el-tab-pane>
      <el-tab-pane label="回收站" name="six">回收站</el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { getList } from "../../utils/http";
export default {
  name: "",
  data() {
    return {
      activeName: "first",
      tableData: [],
      tableDataCopy: [],
      pageIndex: 1,
      pageSize: 10,
      input: "",
    };
  },
  methods: {
    handleSelectionChange() {},
    handleSizeChange(size) {
      this.pageSize = size;
    },
    handleCurrentChange(index) {
      this.pageIndex = index;
    },
    search() {
      if(!this.input) {
        alert('不能空搜索');
        return
      }
      this.tableData = this.tableDataCopy.filter(item => {
        return item.title.includes(this.input)
      })
    }
  },
  created() {
    getList().then((res) => {
      for (let i = 0; i < res.data.result.length; i++) {
        res.data.result[i].checked = false;
      }
      this.tableData = res.data.result;
      this.tableDataCopy = JSON.parse(JSON.stringify(res.data.result))
      console.log(res.data.result);
    });
  },
  mounted() {},
  components: {},
  computed: {
    reData() {
      return this.tableData.slice(
        (this.pageIndex - 1) * this.pageSize,
        this.pageIndex * this.pageSize
      );
    },
  },
};
</script>

<style scoped>
</style>